﻿@using CkSoftware.GroupMe.Sdk.TestWeb.Helpers
@model CkSoftware.GroupMe.Sdk.TestWeb.Models.IndexAllBotsModel
@{
    ViewBag.Title = "List of all bots";
}

<div class="page-header">
    <h1>List of all currently living bots</h1>
</div>

@if (!SessionConfiguration.IsConfigValueIsSet<string>(SessionConfiguration.GroupMeBotApiKeyConfigKey))
{
    <h2>Configuration required</h2>
    <p>Before you can start here, you have to configure your GroupMe API Key @Html.Bootstrap().ActionLink("here", "Index").</p>
}
else
{
    using (var table = Html.Bootstrap().Begin(new Table().Striped()))
    {
        using (table.BeginHeader())
        {
            <tr>
                <th>Avatar</th>
                <th>Name</th>
                <th>Callback URL</th>
                <th>Group Name</th>
                <th>Actions</th>
            </tr>
        }

        using (var body = table.BeginBody())
        {
            foreach (var bot in Model.Bots)
            {
                using (var row = body.BeginRow())
                {
                    @row.Cell(Html.AvatarImageForGroupMePicture(bot.Data.AvatarPicture, bot.Data.Name))
                    @row.Cell(bot.Data.Name)
                    @row.Cell(bot.Data.CallbackUrl)
                    @row.Cell(bot.Data.GroupName)
                    using (@row.BeginCell())
                    {
                        using (var buttonGroup = Html.Bootstrap().Begin(new ButtonGroup()))
                        {
                            @buttonGroup.ActionLinkButton(string.Empty, "DestroyBotById", "Bot").RouteValues(new {botId = bot.Data.Id}).AppendIcon(Icons.remove).Title("Destroy bot")
                            if (!BotHelper.IsBotStarted())
                            {
                                @buttonGroup.ActionLinkButton(string.Empty, "UseBotWithId", "Bot").RouteValues(new {botId = bot.Data.Id}).AppendIcon(Icons.ok).Title("Use this bot for the current session")
                            }
                        }
                    }
                }
            }
        }
    }
}